$(function () {
  init();
})
// 初始化
function init(){
    var id = getParam("id");
    // 确定
    var ajax = new $ax("/leavemanagement/queryID", function (data) {
        // 成功
        if (data.status == "true") {
			
            var list = data.list;
			
			var tempids = "";

			var appListhtml = "";

            for(var i=0; i<list.length; i++){
                if(i == 0 ){
                    tempids = list[i].ids;
                    appListhtml = appListhtml + "<div class=\"well\"><address><h4>审批人:"+list[i].approvalName+"</h4><h4>审批状态:"+isNull(list[i].approvalState)+"</h4> <h4>审批时间:"+formatDateTimeYMDHM(list[i].approvalTime)+"</h4> <h4>审批意见:"+isNull(list[i].approvalOpinion)+"</h4> </address>";
                }else if(i == list.length-1 ){
                    if(tempids == list[i].ids){
                        appListhtml = appListhtml + "<address><h4>审批人:"+list[i].approvalName+"</h4><h4>审批状态:"+isNull(list[i].approvalState)+"</h4> <h4>审批时间:"+formatDateTimeYMDHM(list[i].approvalTime)+"</h4> <h4>审批意见:"+isNull(list[i].approvalOpinion)+"</h4> </address>"
                    }else {
                        tempids = list[i].ids;
                        appListhtml = appListhtml + "</div> <div class=\"well\"><address><h4>审批人:"+list[i].approvalName+"</h4><h4>审批状态:"+isNull(list[i].approvalState)+"</h4> <h4>审批时间:"+formatDateTimeYMDHM(list[i].approvalTime)+"</h4> <h4>审批意见:"+isNull(list[i].approvalOpinion)+"</h4> </address>"
                    }
                }else {
                    if(tempids == list[i].ids){
                        appListhtml = appListhtml + "<address><h4>审批人:"+list[i].approvalName+"</h4><h4>审批状态:"+isNull(list[i].approvalState)+"</h4> <h4>审批时间:"+formatDateTimeYMDHM(list[i].approvalTime)+"</h4> <h4>审批意见:"+isNull(list[i].approvalOpinion)+"</h4> </address>"
                    }else {
                        tempids = list[i].ids;
                        appListhtml = appListhtml +"</div> <div class=\"well\"><address><h4>审批人:"+list[i].approvalName+"</h4><h4>审批状态:"+isNull(list[i].approvalState)+"</h4> <h4>审批时间:"+formatDateTimeYMDHM(list[i].approvalTime)+"</h4> <h4>审批意见:"+isNull(list[i].approvalOpinion)+"</h4> </address>"
                    }
                }
            }

            $("#approvalList").append(appListhtml);
            var approvalList = $("#approvalList");
            var ii = "";
        } else {
            alert("查看失败");
        }

    }, function (data) {
        // 失败
        alert("访问失败");
        errorAjax();
        alert("查看失败");
    });

    ajax.setToken(cookie.get("token"));
    ajax.set("id", id);
    ajax.start();
}


/**
 * 获取指定的URL参数值
 * URL:http://www.xxxxxxx.com/index?name=tyler
 * 参数：paramName URL参数
 * 调用方法:getParam("name")
 * 返回值:tyler
 */
function getParam(paramName) {
    paramValue = "", isFound = !1;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
        arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
        while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
    }
    return paramValue == "" && (paramValue = null), paramValue
}
function isNull(temp) {
    if(temp == null){
        return "";
    }else {
        return temp;
    }
}

//return y + '-' + m + '-' + d +' '+h+':'+minute;
function formatDateTimeYMDHM(inputTime) {
    if(inputTime == null){
        return "";
    }else {
        var date = new Date(inputTime);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        // return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
        return y + '-' + m + '-' + d +' '+h+':'+minute;
    }
};